﻿Public Sub ReplaceCrmTypes()
    '
    ' DO NOT CHANGE THE ORDER OF THESE OPERATIONS.
    '
    MySearchReplace("CrmMoneyProperty", "Money", True, False)   ' need to verify
    MySearchReplace("CrmTypes.CreateCrmMoney", "new Money", True, False)
    MySearchReplace("CrmTypes.CreateCustomer", "new EntityReference", True, False)
    MySearchReplace("CrmTypes.CreateLookup", "new EntityReference", True, False)
    MySearchReplace("CrmTypes.CreateMoniker ", "new EntityReference", True, False)
    MySearchReplace("CrmTypes.CreateOwner", "new EntityReference", True, False)
    MySearchReplace("CrmTypes.CreatePicklist", "new OptionSetValue", True, False)
    MySearchReplace("CrmTypes.CreateStatus", "new OptionSetValue", True, False)

    '
    ' RegEx queries
    '
    MySearchReplace("CrmTypes.CreateCrmBoolean\({.+}\)", "\1", False, True)
    MySearchReplace("CrmTypes.CreateCrmDateTime\({.+}\)", "\1", True, True)
    MySearchReplace("CrmTypes.CreateCrmDateTimeFromUser\({.+}\)", "\1", True, True)
    MySearchReplace("CrmTypes.CreateCrmDecimal\({.+}\)", "\1", False, True)
    MySearchReplace("CrmTypes.CreateCrmFloat\({.+}\)", "\1", False, True)
    MySearchReplace("CrmTypes.CreateCrmNumber\({.+}\)", "\1", False, True)
    MySearchReplace("CrmTypes.CreateGuid\({.+}\)", "new Guid\(\1\)", False, True)
    MySearchReplace("CrmTypes.CreateKey\({.+}\)", "\1", False, True)

    MySearchReplace("\(\(CrmBoolean\){.+}\)\.Value", "(bool)\1", False, True)
    MySearchReplace("\(\(CrmDateTime\){.+}\)\.Value", "(DateTime)\1", False, True)
    MySearchReplace("\(\(CrmNumber\){.+}\)\.Value", "(int)\1", False, True)
    MySearchReplace("\(\(DynamicEntity\){.+}\)\.Value", "(Entity)\1", False, True)
    MySearchReplace("\(\(Key\){.+}\)\.Value", "(Guid)\1", False, True)
    MySearchReplace("\(\(Lookup\){.+}\)\.Value", "(EntityReference)\1", False, True)

    MySearchReplace("new CrmNumber\({.+}\)", "\1", False, True)
    MySearchReplace("new CrmBoolean\({.+}\)", "\1", False, True)
    MySearchReplace("new CrmDecimal\({.+}\)", "\1", False, True)
    MySearchReplace("new CrmDouble\({.+}\)", "\1", False, True)
    MySearchReplace("new CrmFloat\({.+}\)", "\1", False, True)

    MySearchReplace("CrmDateTime", "DateTime", True, False)
    MySearchReplace("Customer", "EntityReference", True, False)
    MySearchReplace("Key", "Guid", True, False)
    MySearchReplace("Lookup", "EntityReference", True, False)
    MySearchReplace("Lookup", "EntityReference", True, False)
    MySearchReplace("Lookup", "EntityReference", True, False)
    MySearchReplace("Moniker", "EntityReference", True, False)
    MySearchReplace("Picklist", "OptionSetValue", True, False)

    '
    ' This operation occurs after all of the possible conversions to EntityReference
    ' have completed.
    '
    MySearchReplace("\(\(EntityReference\){.+}\)\.Name", "((EntityReference)\1).LogicalName", False, True)
End Sub